package com.eling.elcms.cater.webapp.controller;

import com.eling.elcms.cater.model.TravelAccountFlow;
import com.eling.elcms.cater.model.view.TravelAccountFlowView;
import com.eling.elcms.cater.service.ITravelAccountFlowService;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class TravelAccountFlowController extends BaseFormController {
	@Autowired
	private ITravelAccountFlowService accountFlowService;

	@RequestMapping("/api/cate/travelaccountflow/search*")
	@ResponseBody
	public List<TravelAccountFlow> sreach(@ModelAttribute SearchCondition sc, @ModelAttribute TravelAccountFlow cond) {
		sc.setQueryCondition(cond);
		return accountFlowService.search(sc);
	}

	@RequestMapping("/api/cate/travelaccountflow/query")
	@ResponseBody
	public List<TravelAccountFlow> query(@ModelAttribute TravelAccountFlow cond) {
		return accountFlowService.query(cond);
	}

	@RequestMapping("/api/cate/travelaccountflow/save")
	@ResponseBody
	public TravelAccountFlow save(@ModelAttribute @ModelFilling TravelAccountFlow cond) {
		return accountFlowService.save(cond);
	}
	
	@RequestMapping("/api/cate/travelaccountflow/saveAttendant")
	@ResponseBody
	public TravelAccountFlow saveAttendant(@ModelAttribute @ModelFilling TravelAccountFlow travelAccountFlow) {
		return accountFlowService.saveAttendant(travelAccountFlow);
	}

	@RequestMapping("/api/cate/travelaccountflow/{pkTravelAccountFlow}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkTravelAccountFlow) {
		accountFlowService.remove(pkTravelAccountFlow);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/cate/travelaccountflow/recordflow")
	@ResponseBody
	public TravelAccountFlow recordFlow(@ModelAttribute TravelAccountFlow cond) {
		return accountFlowService.recordFlow(cond);
	}
	
	@RequestMapping("/api/cate/travelaccountflow/employeeCount")
	@ResponseBody
	public List<TravelAccountFlowView> employeeCount(@RequestParam (value="operateDate") Date operateDate,@RequestParam (value="operateDateEnd") Date operateDateEnd) {
		return accountFlowService.employeeCount(operateDate,operateDateEnd);
	}
	
}
